class WsseAuthHeader < SOAP::Header::SimpleHandler
  NAMESPACE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'
  USERNAME  = 'USERNAME'
  PASSWORD  = 'PASSWORD'

  def initialize()
    super(XSD::QName.new(NAMESPACE, 'Security'))
  end

  def on_simple_outbound
    {"UsernameToken" => {"Username" => USERNAME, "Password" => PASSWORD}}
  end
end

#make sure everything is unicode-friendly, just in case
XSD::Charset.encoding = 'UTF8'

endpoints = {
  :indy => 'https://webservice.exacttarget.com/Service.asmx',
  :vegas => 'https://webservice.s4.exacttarget.com/Service.asmx'
}

# The default SOAP::DefaultEndpointUrl can be used or custom end point
endpoint_url = endpoints[:indy] || Soap::DefaultEndpointUrl

# Instantiate a new SOAP request
$driver = Soap.new(endpoint_url)

# enable debug output (showing SOAP XML) if you run this script with ruby -d 
$driver.wiredump_dev = STDOUT if $DEBUG

# Append the authentication onto the SOAP Request
$driver.headerhandler << WsseAuthHeader.new()